package com.newdjk.newdoctor.db.gen;

import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;

import com.newdjk.newdoctor.entity.InfoConverter;
import java.util.List;

import com.newdjk.newdoctor.entity.LoginData;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "LOGIN_DATA".
*/
public class LoginDataDao extends AbstractDao<LoginData, Long> {

    public static final String TABLENAME = "LOGIN_DATA";

    /**
     * Properties of entity LoginData.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", true, "_id");
        public final static Property Phone = new Property(1, String.class, "phone", false, "PHONE");
        public final static Property Type = new Property(2, int.class, "type", false, "TYPE");
        public final static Property List = new Property(3, String.class, "list", false, "LIST");
    }

    private final InfoConverter listConverter = new InfoConverter();

    public LoginDataDao(DaoConfig config) {
        super(config);
    }
    
    public LoginDataDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"LOGIN_DATA\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"PHONE\" TEXT UNIQUE ," + // 1: phone
                "\"TYPE\" INTEGER NOT NULL ," + // 2: type
                "\"LIST\" TEXT);"); // 3: list
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"LOGIN_DATA\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, LoginData entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String phone = entity.getPhone();
        if (phone != null) {
            stmt.bindString(2, phone);
        }
        stmt.bindLong(3, entity.getType());
 
        List list = entity.getList();
        if (list != null) {
            stmt.bindString(4, listConverter.convertToDatabaseValue(list));
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, LoginData entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String phone = entity.getPhone();
        if (phone != null) {
            stmt.bindString(2, phone);
        }
        stmt.bindLong(3, entity.getType());
 
        List list = entity.getList();
        if (list != null) {
            stmt.bindString(4, listConverter.convertToDatabaseValue(list));
        }
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public LoginData readEntity(Cursor cursor, int offset) {
        LoginData entity = new LoginData( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // phone
            cursor.getInt(offset + 2), // type
            cursor.isNull(offset + 3) ? null : listConverter.convertToEntityProperty(cursor.getString(offset + 3)) // list
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, LoginData entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setPhone(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setType(cursor.getInt(offset + 2));
        entity.setList(cursor.isNull(offset + 3) ? null : listConverter.convertToEntityProperty(cursor.getString(offset + 3)));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(LoginData entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(LoginData entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(LoginData entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
}
